package com.zhiyou100.IService;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zhiyou100.entity.TbFunding;
import com.zhiyou100.entity.TbFundingExample;
import com.zhiyou100.entity.TbLike;
import com.zhiyou100.entity.TbLikeExample;
import com.zhiyou100.entity.Tbuspts;
import com.zhiyou100.entity.TbusptsExample;
import com.zhiyou100.entity.Useraudit;
import com.zhiyou100.entity.UserauditExample;
import com.zhiyou100.entity.prosGo.TbProjects;
import com.zhiyou100.entity.prosGo.TbProjectsExample;
import com.zhiyou100.entity.prosGo.TbUser;
import com.zhiyou100.entity.prosGo.TbUserExample;
import com.zhiyou100.entity.prosGo.TbUserExample.Criteria;
import com.zhiyou100.mapper.TbCommentsMapper;
import com.zhiyou100.mapper.TbFundingMapper;
import com.zhiyou100.mapper.TbLikeMapper;
import com.zhiyou100.mapper.TbusptsMapper;
import com.zhiyou100.mapper.UserauditMapper;
import com.zhiyou100.mapper.prosGo.TbProjectsMapper;
import com.zhiyou100.mapper.prosGo.TbUserMapper;
import com.zhiyou100.pojo.TbComments;
import com.zhiyou100.pojo.TbCommentsExample;

@Service("userService")
public class userService implements IuserServiceaaaaa{
	@Resource
	private TbUserMapper userMapper;
	@Resource
	private TbProjectsMapper tbProjectsMapper;
	@Resource
	private TbusptsMapper tbusptsMapper;
	@Resource
	private UserauditMapper userauditMapper;
	@Resource
	private TbFundingMapper tbFundingMapper;
	@Resource
	private TbLikeMapper tbLikeMapper;
	@Resource
	private TbCommentsMapper tbCommentsMapper;
	/**
	 * 
	 * 注册方法
	 * 
	 */
	public boolean addUser(TbUser tbUser) {
		TbUserExample userExample = new TbUserExample();
		userExample.or(userExample.createCriteria().andUsAccountEqualTo(tbUser.getUsAccount()));
		userExample.or(userExample.createCriteria().andUsPhoneEqualTo(tbUser.getUsPhone()));
		List<TbUser> list = userMapper.selectByExample(userExample);
		System.out.println(list.size());
		if(list.size()>0) {
			return false;
		}else {
			tbUser.setUsStatus(1);
			userMapper.insert(tbUser);
			return true;
		}
	}
	
	/**
	 * 
	 * 登录方法
	 * 
	 */
	public TbUser login(TbUser tbUser) {
		TbUserExample tbUserExample=new TbUserExample();
        Criteria criteria = tbUserExample.createCriteria();
        criteria.andUsPhoneEqualTo(tbUser.getUsPhone());
        criteria.andUsPasswordEqualTo(tbUser.getUsPassword());
        return userMapper.selectByExample(tbUserExample).size()>0?userMapper.selectByExample(tbUserExample).get(0):null;
	}
	/**
	 * 
	 * 查询已注册用户方法
	 * 
	 */
	public List<TbUser> queryregist(TbUser tbUser) {
		TbUserExample tbUserExample=new TbUserExample();
        Criteria criteria =tbUserExample.createCriteria();
        if(tbUser.getUsStatus() != null ) {
        	criteria.andUsStatusEqualTo(tbUser.getUsStatus());
        }
        if(tbUser.getUsAccount() != null &&!tbUser.getUsAccount().trim().isEmpty()){
        	criteria.andUsAccountEqualTo(tbUser.getUsAccount());
        }
		return userMapper.selectByExample(tbUserExample);
	}

	/**
	 * 
	 * 查询项目方法
	 * 
	 */
	public List<Tbuspts> queryuser(Tbuspts tbuspts) {
		TbusptsExample tbusptsExample=new TbusptsExample();
        TbusptsExample.Criteria criteria = tbusptsExample.createCriteria();
        criteria.andUsAccountEqualTo(tbuspts.getUsAccount());
        
		return tbusptsMapper.selectByExample(tbusptsExample);
	}
	
	public List<TbUser> queryAcouut(TbUser tbUser) {
		TbUserExample tbUserExample=new TbUserExample();
        Criteria criteria =tbUserExample.createCriteria();
        criteria.andUsAccountEqualTo(tbUser.getUsAccount());
		return userMapper.selectByExample(tbUserExample);
	}

	/**
	 * 
	 * 修改方法
	 */
	public int update(TbUser tbUser) {
		TbUserExample tbUserExample=new TbUserExample();
        Criteria criteria =tbUserExample.createCriteria();
        criteria.andUsAccountEqualTo(tbUser.getUsAccount());
		return userMapper.updateByExampleSelective(tbUser, tbUserExample);
	}

	public boolean addUseraudit(Useraudit useraudit) {
		UserauditExample userauditExample = new UserauditExample();
		userauditExample.or(userauditExample.createCriteria().andAUNameEqualTo(useraudit.getaUName()));
		userauditExample.or(userauditExample.createCriteria().andAUNumEqualTo(useraudit.getaUNum()));
		List<Useraudit> list = userauditMapper.selectByExample(userauditExample);
		if(list.size()>0) {
			return false;
		}else {
			useraudit.setaStatus(0);
			userauditMapper.insert(useraudit);
			return true;
		}
	}

	public boolean addUsera(Useraudit useraudit) {
		userauditMapper.insert(useraudit);
		return true;
	}
	/**
	 * 
	 * 支持项目
	 */
	public List<TbFunding> queryfund(TbFunding tbfunding) {
		TbFundingExample tbFundingExample = new TbFundingExample();
        TbFundingExample.Criteria criteria = tbFundingExample.createCriteria();
        criteria.andFdUsIdEqualTo(tbfunding.getFdUsId());
		return tbFundingMapper.selectByExample(tbFundingExample);
	}

	public List<TbLike> querylike(TbLike tbLike) {
		TbLikeExample tbLikeExample = new TbLikeExample();
		TbLikeExample.Criteria criteria = tbLikeExample.createCriteria();
		criteria.andUIdEqualTo(tbLike.getuId());
		return tbLikeMapper.selectByExample(tbLikeExample);
	}

	public List<TbProjects> querytbProjects(TbProjects tbProjects) {
		TbProjectsExample tbProjectsExample = new TbProjectsExample();
		TbProjectsExample.Criteria criteria = tbProjectsExample.createCriteria();
		criteria.andPsUsIdEqualTo(tbProjects.getPsUsId());
		return tbProjectsMapper.selectByExample(tbProjectsExample);
	}

	public List<TbComments> querytbComment(TbComments tbComments) {
		TbCommentsExample tbCommentsExample = new TbCommentsExample();
		TbCommentsExample.Criteria criteria = tbCommentsExample.createCriteria();
		criteria.andCmUsIdEqualTo(tbComments.getCmUsId());
		return tbCommentsMapper.selectByExample(tbCommentsExample);
	}
}
